import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_core_widget/utils/native/file_picker_native_util.dart';
import 'package:kq_flutter_core_widget/widgets/image/kq_image.dart';
import 'package:kq_flutter_core_widget/widgets/imageBox/kq_image_box.dart';
import 'package:kq_flutter_tv_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_tv_widgets/widgets/dialog/kq_file_picker.dart';
import 'package:kq_flutter_tv_widgets/widgets/imageBox/kq_head_image_view.dart';
import 'package:kq_flutter_tv_widgets_example/resources/Images.dart';

/// 自定义控件演示页面
class CustomExpandView extends StatefulWidget {
  const CustomExpandView({super.key});

  @override
  State<StatefulWidget> createState() {
    return CustomExpandViewState();
  }
}

class CustomExpandViewState extends State<CustomExpandView> {
  ImageUrl? imgUrl = ImageUrl(
      imageType: ImageType.http,
      url: 'https://imgs.699pic.com/01/500/628/783/500628783.jpg!list2x.v1');
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SingleChildScrollView(
          padding: EdgeInsets.symmetric(horizontal: 20.r, vertical: 20.r),
          child: Column(
            children: [
              KqHeadImageView(
                defaultUrl: Images.commonIcAddRemake,
                isCircle: true,
                gradient: const LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomLeft,
                    stops: [0.0, 1.0],
                    colors: [KqThemeColors.textBlue, KqThemeColors.bgWhite]),
                didDelete: () {
                  setState(() {
                    imgUrl = null;
                  });
                },
                didSelected: () {
                  //上传图片
                  KqFilePicker().choosePhoto(context, ((files) {
                    setState(() {
                      KqFile xfile = files.first;
                      imgUrl =
                          ImageUrl(imageType: ImageType.file, url: xfile.filePath ?? '');
                    });
                  }));
                },
                netUrl: imgUrl,
              ),
            ],
          ),
        ));
  }
}
